<?php
/*
<Home Controller> 
Author: Qamar Sheeraz
Date:   05-07-2011
Last Updated by: Qamar Sheeraz
Last Updated on: 06-07-2011
*/

class homeController extends appController
{
	function index()
	{
		$this->set("homeCmd", $this->data['homeCmd']);
		$this -> render('Home');
	}

	function verify()
	{
		
		$res=$this -> home -> verifyLogin($this -> data['usernickname'], 
										  $this -> data['userpassword']);
		$status=0;
		if($res)
		{
			// function to check the user Status
			if($res['userStatus'] == 'Active')
			{
				setcookie('userID_finsol', ' ', time() - (3600*24), '/');
				setcookie('userNickName_finsol', ' ', time() - (3600*24), '/');
			
				$expire = time() + (3600 * 24);
				setcookie('userID_finsol', $res['userID'], $expire , '/');
				setcookie('userNickName_finsol', $res['userNickName'], $expire , '/');
				
				
				/////// updateing last login time
				$fv=array("userLastLoginDate"	=> "NOW()");
				$where=array("userID"	=> $res['userID']);
				$this -> home -> _updateTable("usersInfo", $fv, $where);
				$status=1;
			}
			else
				$status=0;	
		}
		else
			$status=0;

		if($status==1)
		{
			$red = array('page'	 => 'home');
			$this -> redirect($red);
		}
		else
		{
			$red = array('page'	 => 'home',
			 			 'homeCmd'   => 'Your login/password is not valid');
			$this -> redirect($red);
		}
		
	
	}	

	function doLogout()
	{
		setcookie('userID_finsol', ' ', time() - (3600*24), '/');
		setcookie('userNickName_finsol', ' ', time() - (3600*24), '/');
		//Regenerate new session
		session_regenerate_id();
		// redirect to home
		$this -> redirect('home');
	}	
}
?>